package com.deyuanyun.pic.ctrl.controller.dto;

import java.util.Date;

import com.deyuanyun.pic.common.spring.SpringAppliction;
import com.deyuanyun.pic.common.util.StringUtils;
import com.deyuanyun.pic.common.util.poi.annotation.ExcelReadColumn;
import com.deyuanyun.pic.common.util.web.Asserts;
import com.deyuanyun.pic.common.validator.annotations.DataValidate;
import com.deyuanyun.pic.ctrl.controller.dto.validata.EQPTRequestValidata;
import com.deyuanyun.pic.ctrl.controller.dto.validata.EQPTTypeRequestValidata;
import com.deyuanyun.pic.ctrl.controller.dto.validata.RepairSuggestionRequestValidata;
import com.deyuanyun.pic.ctrl.domain.CpRecRecode;
import com.deyuanyun.pic.ctrl.enumeration.EqptTypeEnum;
import com.deyuanyun.pic.ctrl.service.EQPTBaseService;
import com.deyuanyun.pic.settings.domain.util.DomainFieldReflectUtil;
import com.deyuanyun.pic.settings.support.biz.CodeUtil;

/**
 * 阴保设备整改，导入需要整改的设备/建议。
 * @author ChenKui
 * @date 2016-06-20
 *
 */
public class RepairEQPTSuggestExcelVO extends CpRecRecode{

    //异常情况  修复建议    最迟修复时间  检测单位    检测日期    备注
    
    @ExcelReadColumn(indexChar = "A", columnTitle = "设备类型",columnTitleRowNumber = 2,columnTitleCellNumber = "A")
    @DataValidate(notNull = true,myFunction = EQPTTypeRequestValidata.class,myFunctionMessage = "设备类型不是预期的名称")
    private String eqptType_;//设备类型

    @ExcelReadColumn(indexChar = "B", columnTitle = "设备编号",columnTitleRowNumber = 2,columnTitleCellNumber = "B")
    @DataValidate(notNull = true,onlyOne = true,myFunction = EQPTRequestValidata.class,myFunctionMessage = "设备编号或类型有误或者该设备不在该管道范围内")
    private String eqptId_;//设备编号

    @ExcelReadColumn(indexChar = "C", columnTitle = "异常情况",columnTitleRowNumber = 2,columnTitleCellNumber = "C")
    @DataValidate(notNull = true,myFunctionMessage = "")
    private String description;//异常情况 
    
    @ExcelReadColumn(indexChar = "D", columnTitle = "修复建议",columnTitleRowNumber = 2,columnTitleCellNumber = "D")
    @DataValidate(notNull = true,myFunction = RepairSuggestionRequestValidata.class,myFunctionMessage = "数据库无对应值")
    private String repairSuggestion_;//修复建议
    
    @ExcelReadColumn(indexChar = "E", columnTitle = "最迟修复时间",columnTitleRowNumber = 2,columnTitleCellNumber = "E")
    @DataValidate(notNull = true,myFunctionMessage = "")
    private Date lastRepairDate;//最迟维修时间
    
    @ExcelReadColumn(indexChar = "F", columnTitle = "检测单位",columnTitleRowNumber = 2,columnTitleCellNumber = "F")
    @DataValidate(notNull = true,myFunctionMessage = "")
    private String testingCompany;//检测单位

    @ExcelReadColumn(indexChar = "G", columnTitle = "检测日期",columnTitleRowNumber = 2,columnTitleCellNumber = "G")
    @DataValidate(notNull = true,myFunctionMessage = "")
    private Date testingDate;//检测日期
    
    @ExcelReadColumn(indexChar = "H", columnTitle = "备注",columnTitleRowNumber = 2,columnTitleCellNumber = "H")
    @DataValidate(notNull = false,myFunctionMessage = "")
    private String remarks;//备注

    
    
    public void setEqptType_(String eqptType_) {
        EqptTypeEnum eqptType = EqptTypeEnum.getValueByLabel(eqptType_);
        if(eqptType != null){
            setEqptType(eqptType.toString());
        }
        this.eqptType_ = eqptType_;
    }

    public void setEqptId_(String eqptId_) {
        EqptTypeEnum eqptTypeEnum = EqptTypeEnum.getValueByLabel(eqptType_);
        if(eqptTypeEnum == null){
            this.eqptId_ = eqptId_;
            return ;
        }
        
        EQPTBaseService eQPTBaseService = (EQPTBaseService)SpringAppliction.getBean(EQPTBaseService.class);
        @SuppressWarnings("unchecked")
        Object obj = eQPTBaseService.queryObjectByCustomNumber(eqptTypeEnum.getClazz(), (String)eqptId_);
        if(obj != null){
            String eqptId = (String)DomainFieldReflectUtil.getFieldValue(obj, "id");
            setEqptId(eqptId);
            
            String pipeLineId = (String)DomainFieldReflectUtil.getFieldValue(obj, "pipeLineId");
            setPipeLineId(pipeLineId);
            
            String pipeValveroomId = (String)DomainFieldReflectUtil.getFieldValue(obj, "pipeValveroomId");
            setPipeValveroomId(pipeValveroomId);
            
            Long mileage = (Long)DomainFieldReflectUtil.getFieldValue(obj, "mileage");
            setMileage(mileage);
            
            String nagm = (String)DomainFieldReflectUtil.getFieldValue(obj, "nagm");
            setNagm(nagm);
            Long nagmMileage = (Long)DomainFieldReflectUtil.getFieldValue(obj, "nagmMileage");
            setNagmMileage(nagmMileage);
        }
        this.eqptId_ = eqptId_;
        setEqptNumber(eqptId_);
    }

    public void setRepairSuggestion_(String repairSuggestion_) {
        this.repairSuggestion_ = repairSuggestion_;
        String codeId = CodeUtil.getCodeId("REPAIR_SUGGESTED", repairSuggestion_);
        setRepairSuggestion(codeId);
    }
/*
    public void setLastRepairDate_(String lastRepairDate_) {
        try {
            Date d = DateUtil.allStr2Date(lastRepairDate_);
            setLastRepairDate(d);
        } catch (Exception e) {
            //e.printStackTrace();
        }
        this.lastRepairDate_ = lastRepairDate_;
    }

    public void setTestingDate_(String testingDate_) {
        try {
            Date d = DateUtil.allStr2Date(lastRepairDate_);
            setLastRepairDate(d);
        } catch (Exception e) {
            //e.printStackTrace();
        }
        this.testingDate_ = testingDate_;
    }
    */
    
    
    public String getEqptType_() {
        return eqptType_;
    }

    public String getEqptId_() {
        return eqptId_;
    }

    public String getRepairSuggestion_() {
        return repairSuggestion_;
    }

}
